function TreeViewSearchLDAPMessageListener (ldapdatatreeview, index)
{
	this.ldapdatatreeview = ldapdatatreeview;
	this.index = index;
	this.count = 0;
}

TreeViewSearchLDAPMessageListener.prototype.QueryInterface = function(iid)
{
	if (iid.equals(Components.interfaces.nsISupports) || iid.equals(Components.interfaces.nsILDAPMessageListener))
		return this;
	else
		Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
	return null;
}

TreeViewSearchLDAPMessageListener.prototype.onLDAPInit = function(pConn, pStatus)
{
}

TreeViewSearchLDAPMessageListener.prototype.onLDAPMessage = function(pMsg)
{
	switch (pMsg.type)
	{
		case Components.interfaces.nsILDAPMessage.RES_BIND :
			jsdump("Bind result message received");
			var r = pMsg.errorCode == Components.interfaces.nsILDAPErrors.SUCCESS;
			dump("   Succeeded: "+r+"\n");
			break;
		case Components.interfaces.nsILDAPMessage.RES_SEARCH_ENTRY :
			jsdump("Child entry found");
			var hasSubordinates = false;
			try
			{
				var count = new Object();
				var attributes = pMsg.getAttributes(count);
				for (a in attributes)
				{
					jsdump("Attribute: " + attributes[a]);
					if (attributes[a] == "hasSubordinates")
					{
						var values = pMsg.getValues(attributes[a], count);
						if (values[0])
						{
							hasSubordinates = (values[0] == "TRUE");
							jsdump("Value: " + values[0]);
							jsdump("hasSubordinates: " + hasSubordinates);
						}
					}
				}
			} catch (e) {
				jsdump(e);
			}
			jsdump("   DN: "+pMsg.dn);
			var subindex = this.ldapdatatreeview.AddChildToNode(this.index, pMsg.dn, this.count);
			this.count++;
			jsdump("   Results count: "+this.count);
			if (!hasSubordinates)
				this.ldapdatatreeview.SetNodeHasNoChild(subindex);
			break;
			
		case Components.interfaces.nsILDAPMessage.RES_SEARCH_RESULT :
			jsdump("Search end\n");
			jsdump("   Results count: "+this.count);
			if (this.count == 0)
				this.ldapdatatreeview.SetNodeHasNoChild(this.index);
			break;
	}
}
